package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionOracle {

    private static String url = "jdbc:oracle:thin:@//localhost:1522/BASEDL";
    // private static String url =
    // "jdbc:oracle:thin:@//10.105.41.142:1521/BASEDL";
    private static String user = "redline";
    private static String password = "redline";
    private static Connection connect = null;

    public static Connection getInstance() {
	if (connect == null) {
	    try {
		connect = DriverManager.getConnection(url, user, password);
		return connect;
	    } catch (SQLException sqle) {
		sqle.printStackTrace();
	    }
	}
	return connect;
    }

    public static Connection getInstance(String user, String password) {
	if (connect == null) {
	    try {
		System.out.println(user + " : " + password);
		connect = DriverManager.getConnection(url, user, password);
		return connect;
	    } catch (SQLException sqle) {
		sqle.printStackTrace();
	    }
	}
	return connect;
    }

    public static Connection getInstance(String user, String password,
	    String url, int port, String bdd) {
	if (connect == null) {
	    try {
		connect = DriverManager.getConnection("jdbc:oracle:thin:@//"
			+ url + ":" + port + "/" + bdd, user, password);
		return connect;
	    } catch (SQLException sqle) {
		sqle.printStackTrace();
	    }
	}
	return connect;
    }

    public static boolean dropInstance() {
	try {
	    connect.close();
	    connect = null;
	    return true;
	} catch (SQLException e) {
	    e.printStackTrace();
	}
	return false;
    }
}
